<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>库存期初建账管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		function change(){
			debugger
			var url = "${ctx}/vaccinate/bsVaccineBatchno/queryCompanyName";
			var str = $("select[data-line=vaccName]").find("option:selected").text();
			
			$.ajax({
				url:url,
				data:{"vaccineName":str},
				success:function(data){
					debugger
					var html = "<option value=''>--请选择--</option>";
					var htmll ="<option value=''>--请选择--</option>"
					var batchnoT ="_";
					$.each(data,function(i,t){
						if(batchnoT.indexOf(t.batchno) < 0){
						html += "<option>" + t.batchno + "</option>";
						batchnoT += t.batchno +"_";
						}
					});
					
					
					 var companyNameT = "_";
					$.each(data,function(i,t){
						if(companyNameT.indexOf(t.companyName) < 0){
							htmll += "<option>" + t.companyName + "</option>";
							companyNameT += t.companyName + "_";
						}
						
					}); 
					
					$("#companyName").html(htmll);
					$("#batchno").html(html);
					$("#companyName").select2();
					$("#batchno").select();
				}
				
			});
		}
		
		
		function add(){
			
			location.href="${ctx}/vaccinate/bsVaccineInfo/form";
			
		}
		
		function query(){
			
			var str = $("select[data-line=vaccName]").find("option:selected").text();
			//alert(str+":"+$("#companyName").text()+":"+$("#batchno").find("option:selected").text());
			var url = "${ctx}/vaccinate/bsVaccineBatchno/query";
			$("#searchForm").attr("action",url);
			$("#searchForm").submit();
			$("#searchForm").attr("action","${ctx}/vaccinate/bsVaccineBatchno/");
		/* 	$.ajax({
				url : url,
				data : {"bsVaccineInfo.vaccineName" : str,"bsVaccineInfo.companyName" : $("#companyName").text(),"batchno"  : $("#batchno").find("option:selected").text()}
				
			}); */
		}
		
		function getBatchno(){
			var str = $("select[data-line=vaccName]").find("option:selected").text();
			var companyName = $("#companyName").val();
			var url = "${ctx}/vaccinate/bsVaccineBatchno/queryBatchno";
			$.ajax({
				url : url,
				data : {"vaccineName" : str,"companyName" :companyName},
				success : function(data){
					var html = "<option>--请选择--</option>";
					$.each(data,function(i,t){
						html +="<option>"+t.batchno+"</option>";
					})
					$("#batchno").html(html);
				}
			})
		}
		function union(id){
// 			alert(id);
			window.parent.addRow(id);
		}
		
		function closeLayer(){
 			var index=parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		}
	</script>
	<style type="text/css">
		body{
		padding:20px;
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="javascript:;">疫苗批次信息查询</a></li>
		
	</ul>
	<form id="searchForm"  action="${ctx}/vaccinate/bsVaccineBatchno/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<div class="breadcrumb">
			<table class="table table-bordered">
				<tr>
					<th>疫苗名称:</th>
					<td>
						<select data-line="vaccName"  name="vaccineName" class="span2" onchange="change()">
						<option value="">--请选择--</option>
						<c:forEach var="bsVaccineBatchno" items="${vaccinates}">
						<option>${bsVaccineBatchno.vaccineName}</option>
						</c:forEach>
						</select>
					</td>
					<th>生产企业：</th>
					<td>
						<select id="companyName" name="companyName" onchange="getBatchno()" class="span2">
						<option value="" >--请选择--</option>
						<c:forEach var="bsVaccineBatchno" items="${companys}">
						<option>${bsVaccineBatchno.companyName}</option>
						</c:forEach>
						</select>
					</td>
					<th>疫苗批号：</th>
					<td>
						<select id="batchno" name="batchno" class="span2">
						<option value="" > --请选择--	</option>
						</select>
					</td>
				</tr>
			</table>
		</div>
		<ul class="ul-form breadcrumb">
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="button" onclick="query()" value="查询"/></li>
			<li class="btns"><input id="" class="btn btn-primary" onclick="add()"  type="button" value="新增批号"/></li>
			<li class="btns"><button id="" class="btn btn-primary" onclick="closeLayer()" type="button">关闭窗口</button></li>
			
			<li class="clearfix"></li>
		</ul>
	</form>
	
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed" >
		<thead>
			<tr>
				<shiro:hasPermission name="vaccinate:bsProduct:edit"><th>操作</th></shiro:hasPermission>
				<th>疫苗名称</th>
				<th>疫苗生产企业</th>
				<th>疫苗批号</th>
				<th>有效日期</th>
				<th>规格(剂/支或粒)</th>
				<th>剂量</th>
				<th>批准文号</th>
				<th>批签发合格证明编号</th>
			</tr>
		</thead>
		<tbody id="tbody">
		<c:forEach items="${page.list}" var="bsVaccineBatchno">
			<tr>
				<td>
					
					<input type="button" style="border:none;background-color:#ffffff " onclick="union('${bsVaccineBatchno.id}')" value="关联"/>
				</td>
				<td>
					${bsVaccineBatchno.vaccineName}
				</td>
				<td>
					${bsVaccineBatchno.companyName}
				</td>
				<td>
					${bsVaccineBatchno.batchno}
				</td>
				<td>
				<fmt:formatDate value="${bsVaccineBatchno.outBoundDate}" pattern="yyyy-MM-dd"/>
				</td>
				<td>
					${bsVaccineBatchno.spec}
				</td>
				<td>
					${bsVaccineBatchno.dose}
				</td>
				
				<td>
				<c:if test="${bsVaccineBatchno.customBillNo!=null}">
					${bsVaccineBatchno.customBillNo}
				</c:if>
				</td>
				<td>
					${bsVaccineBatchno.certifiCode}
				</td>
				
			</tr>
		</c:forEach>
		</tbody>
	</table>
	
	<div class="pagination">${page}</div>
</body>
</html>